package net.linku.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Bean(name = "adminDataSource")
    public DataSource adminDataSource() {
        return DataSourceBuilder.create()
                .url("jdbc:mysql://localhost:3306/linku_admin?useSSL=false&serverTimezone=Asia/Shanghai")
                .username("root")
                .password("root")
                .driverClassName("com.mysql.cj.jdbc.Driver")
                .build();
    }

    @Bean(name = "portalDataSource")
    public DataSource portalDataSource() {
        return DataSourceBuilder.create()
                .url("jdbc:mysql://localhost:3306/linku_portal?useSSL=false&serverTimezone=Asia/Shanghai")
                .username("root")
                .password("root")
                .driverClassName("com.mysql.cj.jdbc.Driver")
                .build();
    }

    @Bean(name = "adminJdbcTemplate")
    public JdbcTemplate adminJdbcTemplate(@Qualifier("adminDataSource") DataSource adminDataSource) {
        return new JdbcTemplate(adminDataSource);
    }

    @Bean(name = "portalJdbcTemplate")
    public JdbcTemplate portalJdbcTemplate(@Qualifier("portalDataSource") DataSource portalDataSource) {
        return new JdbcTemplate(portalDataSource);
    }
}
